<?php
namespace MyProject\EhrBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface,
    My\EhrBundle\Entity\MasterInstitution;

class MasterInstitutionFixtures implements FixtureInterface
{
    public function load($em)
    {
        $institutesNames = array();
        $institutesNames[] = 'University Of California';
        $institutesNames[] = 'Barkeley University';
        $institutesNames[] = 'Nin Ji Ying University';
        $institutesNames[] = 'Universitas Gunadarma';
        $institutesNames[] = 'Universitas Indonesia';
        $institutesNames[] = 'Instut Teknologi Bandung';
        $institutesNames[] = 'Universitas Gadjah Mada';
        $institutesNames[] = 'Berlin University';
        $institutesNames[] = 'Nah Yang University';
        $institutesNames[] = 'Yokohama University';
        $institutesNames[] = 'Hiroshima Gunadarma';
        $institutesNames[] = 'Takasimura University';
        $institutesNames[] = 'Instut Teknologi Semarang';
        $institutesNames[] = 'Universitas Islam Negeri Jakarta';

        foreach( $institutesNames as $universityName )
        {
            $this->_createInstitution( $this->_createInstitutionPropertyArray($universityName), $em);
        }
        $em->flush();
    }
    private function _createInstitutionPropertyArray(
            $name,
            $type = 'University',
            $address = 'Benteng Rotherdam Street 2156',
            $city = 'California',
            $fax = '021-333-890-234',
            $mail = 'sample@example-institute.edu',
            $website = 'http://www.sample-intitute.edu',
            $desc = 'Sample Institution Description'
            )
    {
        return array( $name, $type, $address, $city, $fax, $mail, $website, $desc );
    }
    private function _createInstitution($data, $em)
    {
        $institution = new MasterInstitution();
        $institution->setInstitutionName($data[0]);
        $institution->setInstitutionType($data[1]);
        $institution->setAddress($data[2]);
        $institution->setCity($data[3]);
        $institution->setFax($data[4]);
        $institution->setMail($data[5]);
        $institution->setWebsite($data[6]);
        $institution->setDescription($data[7]);
        $em->persist($institution);
    }
}
?>
